


function jumpOpenName(flowId,step,runId,realPrcsId) {
    window.open('/workflow/work/workformPreView?flowId='+flowId+'&flowStep='+step+'&runId='+runId+'&prcsId='+realPrcsId);
}
function jumpOpenType(e,flowId,runId) {
    if($(e).attr('tableName')=='BUDGETTYPE'){
        window.open('/workflow/work/workformPreView?flowId='+flowId+'&tableName=budget&runId='+runId);
    }else{
        window.open('/workflow/work/workformPreView?flowId='+flowId+'&runId='+runId);

    }
}

function jumpOpenStep(flowId,runId,me) {
    eventas=$(me).parent().parent().find('.wenhaoTwo');
    window.open('/flowSetting/processDesignToolTwo?flowId='+flowId+'&rilwId='+runId);
}
//转交
$(document).on("click",".editAndDelete0",function(data){
    var dataObject=pageObj.arrs[$(this).attr('data-i')]
    window.open('/flowSetting/processDesignToolTwo?rilwId='+dataObject.runId+'&flowId='+dataObject.flowId);
})


$(document).on('click','.editAndDelete1',function () {//销毁
    var dataObject=pageObj.arrs[$(this).attr('data-i')]
    var arr=[dataObject.runId]
    layer.confirm(delteAlldistrob, {title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:{
                runIdArray:arr,
            },
            url:'/workflow/work/workDestroy',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content:dem_th_DestroySuccess , icon: 1});
                    pageObj.init();
                } else {
                    $.layerMsg({content: dem_th_Failure, icon: 2});
                }

            }
        })
    }, function() {
        layer.closeAll();
    })
})

$(document).on('click','#destory',function () {//全部销毁
    var type = $(this).attr('dataType')
    if(type == 0){
        var data={allDestroy:1}
        var title=deleteAll1;
    }else{
        var arr=[];
        for(var i=0;i<$('.check').length;i++){
            if($('.check').eq(i).is(':checked')){
                arr.push($('.check').eq(i).attr('runId'))
            }
        }
        var data={runIdArray:arr}
        var title=deleteAll2;
    }
    var dataObject=pageObj.arrs[$(this).attr('data-i')]
    layer.confirm(title, {title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:data,
            url:'/workflow/work/workDestroy',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content: dem_th_DestroySuccess, icon: 1});
                    pageObj.init();
                    $('#destory').find('span').html('全部销毁')
                    $('#destory').attr('dataType','0')
                    $('#reset').find('span').html('全部还原')
                    $('#reset').attr('dataType','0')
                } else {
                    $.layerMsg({content: dem_th_Failure, icon: 2});
                }

            }
        })
    }, function() {
        layer.closeAll();
    })
})

$(document).on('click','.check',function(){
    var arr=[]
    for(var i=0;i<$('.check').length;i++){
        if($('.check').eq(i).is(':checked')){
            arr.push($(this).attr('runId'))
        }
    }
    if(arr==""){
        $('#destory').attr('dataType','0')
        $('#destory').find('span').html('全部销毁')
        $('#reset').attr('dataType','0')
        $('#reset').find('span').html('全部还原')
    }else{
        $('#destory').attr('dataType','1')
        $('#destory').find('span').html('销毁')
        $('#reset').attr('dataType','1')
        $('#reset').find('span').html('还原')
    }
})




$(document).on('click','.editAndDelete2',function () {//还原
    var dataObject=pageObj.arrs[$(this).attr('data-i')]
    var arr=[dataObject.runId]
    layer.confirm(returnAll, {title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:{
                runIdArray:arr,
            },
            url:'/workflow/work/workRestore',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content: reductionSuccess, icon: 1});
                    pageObj.init();
                } else {
                    $.layerMsg({content: reductionFailed, icon: 2});
                }

            }
        })
    }, function() {
        layer.closeAll();
    })
})
$(document).on('click','#reset',function () {//全部还原
    var type = $(this).attr('dataType')
    if(type == 0){
        var data={allRestore:1}
        var title=selectAll;
    }else{
        var arr=[];
        for(var i=0;i<$('.check').length;i++){
            if($('.check').eq(i).is(':checked')){
                arr.push($('.check').eq(i).attr('runId'))
            }
        }
        var data={runIdArray:arr}
        var title=selectWork;
    }
    layer.confirm(title, {title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:data,
            url:'/workflow/work/workRestore',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content: reductionSuccess, icon: 1});
                    pageObj.init();
                    $('#destory').find('span').html('全部销毁')
                    $('#destory').attr('dataType','0')
                    $('#reset').find('span').html('全部还原')
                    $('#reset').attr('dataType','0')
                } else {
                    $.layerMsg({content: reductionFailed, icon: 2});
                }

            }
        })
    }, function() {
        layer.closeAll();
    })
})


$(document).on('click','.editAndDelete4',function () {//结束
    var obj=pageObj.arrs[$(this).attr('data-i')]
    //询问框
    layer.confirm(com, {title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:{
                runId:obj.runId,
                flag:2,
                prcsId:obj.prcsId,
                userId:obj.userId,
                flowPrcs:obj.flowPrcs,
                prcsFlag:obj.prcsFlag
            },
            url:'/workflow/work/updateState',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content: chegon, icon: 1});
                    pageObj.init();
                } else {
                    $.layerMsg({content: shib, icon: 2});
                }

            }
        })
    }, function() {
        layer.closeAll();
    })
})

$(document).on('click','.editAndDelete5',function () {//删除
    var obj=pageObj.arrs[$(this).attr('data-i')];
    //询问框
    layer.confirm(qued,{title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:{
                runId:obj.runId,
                flag:1
            },
            url:'/workflow/work/updateState',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content: delc, icon: 1});
                    pageObj.init();
                } else {
                    $.layerMsg({content: delf, icon: 2});
                }

            }
        })
    }, function(){
        layer.closeAll();
    });
})


//流程分类递归
function queryChild_flow(datas,str_li,level){
    for(var i=0;i<datas.length;i++){

        var className="levelleft"+level;
        if(datas[i].sortName=='未定义'){
            str_li+='<option value="'+datas[i].sortNo+'">'+datas[i].sortName+'</option>'
        }else{
            str_li+='<option value="'+datas[i].sortNo+'">'+datas[i].sortName+'</option>'
        }

        /*   console.log(datas[i].childs); */
        if(datas[i].childs!=null){
            str_li = queryChild_flow(datas[i].childs,str_li,level+1);
        }
    }
    return str_li;
}
$(function(){
    // pageObj.init();
    $("#addUser").on("click",function(){
        user_id='user';
        $.popWindow("../../common/selectUser?0");
    });
    $("#clearUser").on("click",function(){
        $("#user").val("");
        $("#user").attr('user_id','');
    })
//    点击查询
    $('#query').click(function(){
        if($('[name="flowName"]').val()==""){
            $('[name="flowName"]').attr('dataType',null)
        }
        if($('#user').val()!=""){
            pageObj.data.beginUser=$('#user').attr("user_Id").replace(',','');
        }else{
            pageObj.data.beginUser=null
        }
        pageObj.data.page=1;
        pageObj.data.flowId=$('[name="flowName"]').attr('dataType');
        pageObj.data.runId=$('[name="runId"]').val();
        pageObj.data.runName=$('[name="runName"]').val();
        pageObj.data.beginTime=$('#startTime').val();
        pageObj.data.endTime=$('#endTime').val();

        pageObj.init();
    })

    $("#outport").click(function () {
        if($('[name="flowName"]').val()==""){
            $('[name="flowName"]').attr('dataType','0')
        }
        window.location.href='../../workflow/work/monitoring?output=1&flowId='+$('[name="flowId"]').val()
            +'&runId='+$('[name="runId"]').val()+'&runName='+$('[name="runName"]').val()
            +'&workLevel='+$('[name="workLevel"]').val()+'&status='+$('[name="status"]').val()
            +'&userId='+$('[name="userId"]').attr("user_Id");
    })

})